<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>webdoc</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            webdoc
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li class="active"><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-dva.html">30.cms-10-dva</a></li><li><a href="../html/30.cms-11-front.html">30.cms-11-front</a></li><li><a href="../html/31.cms-12-api.html">31.cms-12-api</a></li><li><a href="../html/31.cms-13-front.html">31.cms-13-front</a></li><li><a href="../html/31.cms-14-deploy.html">31.cms-14-deploy</a></li><li><a href="../html/32.ant.html">32.ant</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. 渲染状态">1. 渲染状态</a></li><li><a href="#t12. 提高数据修改的门槛">2. 提高数据修改的门槛</a></li><li><a href="#t23.封装仓库">3.封装仓库</a></li><li><a href="#t34. 监控数据变化">4. 监控数据变化</a></li><li><a href="#t45.纯函数">5.纯函数</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. &#x6E32;&#x67D3;&#x72B6;&#x6001;">1. &#x6E32;&#x67D3;&#x72B6;&#x6001; <a href="#t01. &#x6E32;&#x67D3;&#x72B6;&#x6001;"> # </a></h2>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> appState={
    <span class="hljs-attr">title</span>: {<span class="hljs-attr">color</span>: <span class="hljs-string">&apos;red&apos;</span>,<span class="hljs-attr">text</span>: <span class="hljs-string">&apos;&#x6807;&#x9898;&apos;</span>},
    <span class="hljs-attr">content</span>:{<span class="hljs-attr">color</span>:<span class="hljs-string">&apos;green&apos;</span>,<span class="hljs-attr">text</span>:<span class="hljs-string">&apos;&#x5185;&#x5BB9;&apos;</span>}
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">renderTitle</span>(<span class="hljs-params">title</span>) </span>{
    <span class="hljs-keyword">let</span> titleEle=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;#title&apos;</span>);
    titleEle.innerHTML=title.text;
    titleEle.style.color=title.color;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">renderContent</span>(<span class="hljs-params">content</span>) </span>{
    <span class="hljs-keyword">let</span> contentEle=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;#content&apos;</span>);
    contentEle.innerHTML=content.text;
    contentEle.style.color=content.color;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">renderApp</span>(<span class="hljs-params">appState</span>) </span>{
    renderTitle(appState.title);
    renderContent(appState.content);
}
renderApp(appState);
</code></pre>
<h2 id="t12. &#x63D0;&#x9AD8;&#x6570;&#x636E;&#x4FEE;&#x6539;&#x7684;&#x95E8;&#x69DB;">2. &#x63D0;&#x9AD8;&#x6570;&#x636E;&#x4FEE;&#x6539;&#x7684;&#x95E8;&#x69DB; <a href="#t12. &#x63D0;&#x9AD8;&#x6570;&#x636E;&#x4FEE;&#x6539;&#x7684;&#x95E8;&#x69DB;"> # </a></h2>
<ul>
<li>&#x4E00;&#x65E6;&#x6570;&#x636E;&#x53EF;&#x4EE5;&#x4EFB;&#x610F;&#x4FEE;&#x6539;&#xFF0C;&#x6240;&#x6709;&#x5BF9;&#x5171;&#x4EAB;&#x72B6;&#x6001;&#x7684;&#x64CD;&#x4F5C;&#x90FD;&#x662F;&#x4E0D;&#x53EF;&#x9884;&#x6599;&#x7684;</li>
<li>&#x6A21;&#x5757;&#x4E4B;&#x95F4;&#x9700;&#x8981;&#x5171;&#x4EAB;&#x6570;&#x636E;&#x548C;&#x6570;&#x636E;&#x53EF;&#x80FD;&#x88AB;&#x4EFB;&#x610F;&#x4FEE;&#x6539;&#x5BFC;&#x81F4;&#x4E0D;&#x53EF;&#x9884;&#x6599;&#x7684;&#x7ED3;&#x679C;&#x4E4B;&#x95F4;&#x6709;&#x77DB;&#x76FE;</li>
<li>&#x6240;&#x6709;&#x5BF9;&#x6570;&#x636E;&#x7684;&#x64CD;&#x4F5C;&#x5FC5;&#x987B;&#x901A;&#x8FC7; dispatch &#x51FD;&#x6570;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> appState={
    <span class="hljs-attr">title</span>: {<span class="hljs-attr">color</span>: <span class="hljs-string">&apos;red&apos;</span>,<span class="hljs-attr">text</span>: <span class="hljs-string">&apos;&#x6807;&#x9898;&apos;</span>},
    <span class="hljs-attr">content</span>:{<span class="hljs-attr">color</span>:<span class="hljs-string">&apos;green&apos;</span>,<span class="hljs-attr">text</span>:<span class="hljs-string">&apos;&#x5185;&#x5BB9;&apos;</span>}
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">renderTitle</span>(<span class="hljs-params">title</span>) </span>{
    <span class="hljs-keyword">let</span> titleEle=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;#title&apos;</span>);
    titleEle.innerHTML=title.text;
    titleEle.style.color=title.color;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">renderContent</span>(<span class="hljs-params">content</span>) </span>{
    <span class="hljs-keyword">let</span> contentEle=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;#content&apos;</span>);
    contentEle.innerHTML=content.text;
    contentEle.style.color=content.color;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">renderApp</span>(<span class="hljs-params">appState</span>) </span>{
    renderTitle(appState.title);
    renderContent(appState.content);
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">dispatch</span>(<span class="hljs-params">action</span>) </span>{
    <span class="hljs-keyword">switch</span> (action.type) {
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;UPDATE_TITLE_COLOR&apos;</span>:
            appState.title.color=action.color;    
            <span class="hljs-keyword">break</span>;    
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;UPDATE_CONTENT_CONTENT&apos;</span>:
            appState.content.text=action.text;
            <span class="hljs-keyword">break</span>;
        <span class="hljs-keyword">default</span>:
            <span class="hljs-keyword">break</span>;    
    }
}
dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;UPDATE_TITLE_COLOR&apos;</span>,<span class="hljs-attr">color</span>:<span class="hljs-string">&apos;purple&apos;</span>});
dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;UPDATE_CONTENT_CONTENT&apos;</span>,<span class="hljs-attr">text</span>:<span class="hljs-string">&apos;&#x65B0;&#x6807;&#x9898;&apos;</span>});

renderApp(appState);
</code></pre>
<h2 id="t23.&#x5C01;&#x88C5;&#x4ED3;&#x5E93;">3.&#x5C01;&#x88C5;&#x4ED3;&#x5E93; <a href="#t23.&#x5C01;&#x88C5;&#x4ED3;&#x5E93;"> # </a></h2>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">renderTitle</span>(<span class="hljs-params">title</span>) </span>{
    <span class="hljs-keyword">let</span> titleEle=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;#title&apos;</span>);
    titleEle.innerHTML=title.text;
    titleEle.style.color=title.color;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">renderContent</span>(<span class="hljs-params">content</span>) </span>{
    <span class="hljs-keyword">let</span> contentEle=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;#content&apos;</span>);
    contentEle.innerHTML=content.text;
    contentEle.style.color=content.color;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">renderApp</span>(<span class="hljs-params">appState</span>) </span>{
    renderTitle(appState.title);
    renderContent(appState.content);
}


<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createStore</span>(<span class="hljs-params">reducer</span>) </span>{
    <span class="hljs-keyword">let</span> state;
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getState</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">return</span> state;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">dispatch</span>(<span class="hljs-params">action</span>) </span>{
        state=reducer(state,action);
    }
    dispatch({});
    <span class="hljs-keyword">return</span> {
        getState,
        dispatch
    }

}
<span class="hljs-keyword">let</span> initState={
    <span class="hljs-attr">title</span>: {<span class="hljs-attr">color</span>: <span class="hljs-string">&apos;red&apos;</span>,<span class="hljs-attr">text</span>: <span class="hljs-string">&apos;&#x6807;&#x9898;&apos;</span>},
    <span class="hljs-attr">content</span>:{<span class="hljs-attr">color</span>:<span class="hljs-string">&apos;green&apos;</span>,<span class="hljs-attr">text</span>:<span class="hljs-string">&apos;&#x5185;&#x5BB9;&apos;</span>}
}
<span class="hljs-keyword">let</span> reducer=<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">state=initState,action</span>) </span>{
    <span class="hljs-keyword">switch</span> (action.type) {
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;UPDATE_TITLE_COLOR&apos;</span>:
            <span class="hljs-keyword">return</span> {...state,<span class="hljs-attr">title</span>: {...state.title,<span class="hljs-attr">color</span>:action.color}};
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;UPDATE_CONTENT_CONTENT&apos;</span>:
        <span class="hljs-keyword">return</span> {...state,<span class="hljs-attr">content</span>: {...state.content,<span class="hljs-attr">text</span>:action.text}};    
            <span class="hljs-keyword">break</span>;
        <span class="hljs-keyword">default</span>:
            <span class="hljs-keyword">return</span> state;    
    }
}
<span class="hljs-keyword">let</span> store=createStore(reducer);
renderApp(store.getState());
setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    store.dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;UPDATE_TITLE_COLOR&apos;</span>,<span class="hljs-attr">color</span>:<span class="hljs-string">&apos;purple&apos;</span>});
    store.dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;UPDATE_CONTENT_CONTENT&apos;</span>,<span class="hljs-attr">text</span>:<span class="hljs-string">&apos;&#x65B0;&#x6807;&#x9898;&apos;</span>});
    renderApp(store.getState());
},<span class="hljs-number">2000</span>);
</code></pre>
<h2 id="t34. &#x76D1;&#x63A7;&#x6570;&#x636E;&#x53D8;&#x5316;">4. &#x76D1;&#x63A7;&#x6570;&#x636E;&#x53D8;&#x5316; <a href="#t34. &#x76D1;&#x63A7;&#x6570;&#x636E;&#x53D8;&#x5316;"> # </a></h2>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">renderTitle</span>(<span class="hljs-params">title</span>) </span>{
    <span class="hljs-keyword">let</span> titleEle=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;#title&apos;</span>);
    titleEle.innerHTML=title.text;
    titleEle.style.color=title.color;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">renderContent</span>(<span class="hljs-params">content</span>) </span>{
    <span class="hljs-keyword">let</span> contentEle=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;#content&apos;</span>);
    contentEle.innerHTML=content.text;
    contentEle.style.color=content.color;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">render</span>(<span class="hljs-params"></span>) </span>{
    renderTitle(store.getState().title);
    renderContent(store.getState().content);
}


<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createStore</span>(<span class="hljs-params">reducer</span>) </span>{
    <span class="hljs-keyword">let</span> state;
    <span class="hljs-keyword">let</span> listeners=[];
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getState</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">return</span> state;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">dispatch</span>(<span class="hljs-params">action</span>) </span>{
        state=reducer(state,action);
        listeners.forEach(<span class="hljs-function"><span class="hljs-params">l</span>=&gt;</span>l());
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">subscribe</span>(<span class="hljs-params">listener</span>) </span>{
        listeners.push(listener);
        <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
            listeners = listeners.filter(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> item!=listener);
            <span class="hljs-built_in">console</span>.log(listeners);
        }
    }
    dispatch({});
    <span class="hljs-keyword">return</span> {
        getState,
        dispatch,
        subscribe
    }

}
<span class="hljs-keyword">let</span> initState={
    <span class="hljs-attr">title</span>: {<span class="hljs-attr">color</span>: <span class="hljs-string">&apos;red&apos;</span>,<span class="hljs-attr">text</span>: <span class="hljs-string">&apos;&#x6807;&#x9898;&apos;</span>},
    <span class="hljs-attr">content</span>:{<span class="hljs-attr">color</span>:<span class="hljs-string">&apos;green&apos;</span>,<span class="hljs-attr">text</span>:<span class="hljs-string">&apos;&#x5185;&#x5BB9;&apos;</span>}
}
<span class="hljs-keyword">let</span> reducer=<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">state=initState,action</span>) </span>{
    <span class="hljs-keyword">switch</span> (action.type) {
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;UPDATE_TITLE_COLOR&apos;</span>:
            <span class="hljs-keyword">return</span> {...state,<span class="hljs-attr">title</span>: {...state.title,<span class="hljs-attr">color</span>:action.color}};
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;UPDATE_CONTENT_CONTENT&apos;</span>:
        <span class="hljs-keyword">return</span> {...state,<span class="hljs-attr">content</span>: {...state.content,<span class="hljs-attr">text</span>:action.text}};    
            <span class="hljs-keyword">break</span>;
        <span class="hljs-keyword">default</span>:
            <span class="hljs-keyword">return</span> state;    
    }
}
<span class="hljs-keyword">let</span> store=createStore(reducer);
render();
<span class="hljs-keyword">let</span> unsubscribe = store.subscribe(render);
setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    store.dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;UPDATE_TITLE_COLOR&apos;</span>,<span class="hljs-attr">color</span>:<span class="hljs-string">&apos;purple&apos;</span>});
    unsubscribe();
    store.dispatch({<span class="hljs-attr">type</span>:<span class="hljs-string">&apos;UPDATE_CONTENT_CONTENT&apos;</span>,<span class="hljs-attr">text</span>:<span class="hljs-string">&apos;&#x65B0;&#x6807;&#x9898;&apos;</span>});
},<span class="hljs-number">2000</span>);
</code></pre>
<h2 id="t45.&#x7EAF;&#x51FD;&#x6570;">5.&#x7EAF;&#x51FD;&#x6570; <a href="#t45.&#x7EAF;&#x51FD;&#x6570;"> # </a></h2>
<p>&#x7EAF;&#x51FD;&#x6570;&#x5F88;&#x4E25;&#x683C;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x4F60;&#x51E0;&#x4E4E;&#x9664;&#x4E86;&#x8BA1;&#x7B97;&#x6570;&#x636E;&#x4EE5;&#x5916;&#x4EC0;&#x4E48;&#x90FD;&#x4E0D;&#x80FD;&#x5E72;&#xFF0C;&#x8BA1;&#x7B97;&#x7684;&#x65F6;&#x5019;&#x8FD8;&#x4E0D;&#x80FD;&#x4F9D;&#x8D56;&#x9664;&#x4E86;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x4EE5;&#x5916;&#x7684;&#x6570;&#x636E;&#x3002;</p>
<ul>
<li>&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x53EA;&#x4F9D;&#x8D56;&#x4E8E;&#x5B83;&#x7684;&#x53C2;&#x6570;</li>
<li>&#x51FD;&#x6570;&#x6267;&#x884C;&#x8FC7;&#x7A0B;&#x6CA1;&#x6709;&#x526F;&#x4F5C;&#x7528;,&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x6267;&#x884C;&#x8FC7;&#x7A0B;&#x5BF9;&#x4EA7;&#x751F;&#x4E86;&#x5916;&#x90E8;&#x53EF;&#x89C2;&#x5BDF;&#x7684;&#x53D8;&#x5316;&#x90A3;&#x4E48;&#x5C31;&#x8BF4;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x662F;&#x6709;&#x526F;&#x4F5C;&#x7528;&#x7684;<ul>
<li>&#x8C03;&#x7528; DOM API &#x4FEE;&#x6539;&#x9875;&#x9762;</li>
<li>&#x53D1;&#x9001;&#x4E86; Ajax &#x8BF7;&#x6C42;</li>
</ul>
</li>
</ul>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
